<!-- 参数配置编辑表单 -->
<template>
  <q-card style="width: 400px">
    <!-- 标题 -->
    <q-toolbar>
      <q-toolbar-title>{{ title }}</q-toolbar-title> <q-btn v-close-popup icon="close" round flat />
    </q-toolbar>
    <q-separator />

    <!-- 内容 -->
    <q-card-section style="min-height: 250px">
      <q-form ref="formRef">
        <q-input v-model="dto.configKey" label="参数编码" :rules="[required]" :readonly="readonly || isEdit" />
        <q-input v-model="dto.configName" label="参数名称" :rules="[required]" :readonly="readonly" />
        <q-input v-model="dto.configValue" label="参数值" :rules="[required]" :readonly="readonly" />
        <q-input v-model="dto.remark" label="备注说明" type="textarea" rows="2" :readonly="readonly" />
      </q-form>
    </q-card-section>
    <q-separator />

    <!-- 操作 -->
    <q-card-actions v-if="!readonly">
      <q-checkbox v-model="closeAfterSave" label="保存后关闭" />
      <q-space />
      <q-btn v-close-popup>取消</q-btn>
      <q-btn color="primary" icon="save" :disable="loading" @click="handleSubmit">保存</q-btn>
    </q-card-actions>
  </q-card>
</template>

<script lang="ts" setup>
  import { useCrudForm } from 'src/composables';

  import { required } from 'src/utils/validator';
  import crudApi, { ConfigDto } from 'src/api/system/config';

  // 属性和事件定义
  const props = defineProps({
    id: { type: [String, Number], default: undefined },
    title: { type: String, default: '参数配置表单' },
    readonly: { type: Boolean, default: false },
  });
  const emit = defineEmits(['close', 'after-save']);

  // 表单数据
  const { formRef, isEdit, dto, closeAfterSave, loading, handleSubmit } = useCrudForm<ConfigDto>(crudApi, {}, props, emit);
</script>

<style lang="scss" scoped></style>
